package com.yangji.rxjavatest.repository;

import com.yangji.rxjavatest.base.retrofit.RetrofitHelper;
import com.yangji.rxjavatest.source.api.ApiResponse;
import com.yangji.rxjavatest.source.impl.DeviceService;
import com.yangji.rxjavatest.source.impl.DeviceServiceTest;

import org.reactivestreams.Subscriber;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;


public class DeviceRepository {

    private DeviceService deviceService;

    public DeviceRepository() {
        if (true) {
            deviceService = RetrofitHelper.getInstance().getRetrofit()
                    .create(DeviceService.class);
        } else {
            deviceService = new DeviceServiceTest();
        }
    }


    public Subscriber<ApiResponse> getDeviceToken() {
        deviceService.register("", "", "", "", "")
                .subscribeOn(Schedulers.io())//请求数据的事件发生在io线程
                .observeOn(AndroidSchedulers.mainThread())//请求完成后在主线程更显UI
                .subscribe(new Observer<ApiResponse<String>>() {

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }

                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(ApiResponse<String> stringApiResponse) {

                    }
                });
        return null;

    }
}
